<?php
/**
 * Created by JetBrains PhpStorm.
 * User: zhouyang
 * Date: 13-9-6
 * Time: 下午4:31
 * To change this template use File | Settings | File Templates.
 */
class AdsDB  extends DBReader{
    //获取推广列表
    public function getAdListByType($ad_type_id,$num = NULL){
        $curr_time = date('Y-m-d H:i:s');//取当前时间判断广告是否展示

        $sql = "SELECT i.ad_id,
               i.title,
               i.summary,
               i.link,
               i.picture
               from ads i JOIN ad_times t ON i.ad_id=t.ad_id
               WHERE i.status = 1 and i.ad_type_id=:ad_type_id and t.start_time <= :start_time and t.end_time>=:end_time
               ORDER BY i.ad_id DESC,i.sort DESC";

        if (isset($num) && !empty($num)){
            $sql = "SELECT * FROM ($sql) WHERE 1=1 limit 0,".$num;
        }
        $bind = array('ad_type_id'=>$ad_type_id, 'start_time'=>$curr_time, 'end_time'=>$curr_time);

        return $this->db()->getAll($sql, $bind);
    }
}